<template>
  <view>
    <public-header title="促销历史" isBack="false"></public-header>
    <view class="retail-segmented bg-white" v-if="loaded">
      <rList ref="rList" :page="warConfig.page" :config="warConfig" @on-grid-button="onGridButton"
        @on-list-item-checked="onItemChecked" :condition="condition" style="height: 100%;">
        <template v-slot:rListItem="itemValue">
        </template>
        <template v-slot:rLayoutRight>
        </template>
      </rList>
    </view>
  </view>
</template>

<script>
  import rList from '@/components/retail-list/retail-list.vue'
  import lockscreen from '@/common/mixins/lockscreen.js'
  export default {
    mixins: [lockscreen],
    data() {
      return {
        items: ['库存预警设置', '库存预警商品'],
        current: 0,
        service: "", // 页面service
        type: "update", // 页面编辑模式
        warConfig: {
          hideGridButton: true,
          showRowButton: true,
          srv_app: "mkt",
          appName: 'mkt',
          serviceName: "srvmkt_promotion_activity_select",
          listLayout: "listAndFilter", // listAndDetail listAndFilter  list  batchList   srvretail_stock_early_warning_select
          defaultData: "service-loading", // batch-select   service-loading
          detailPath: "simple", //  simple  基础的； 或者配置页面路由 路由格式待定
          page: {
            pageNo: 1,
            rownumber: 10
          },
          listHeaders: [''],
          // childService: "srvretail_stock_warning_select",
          childKeyCol: "", // 子表数据的主键
          tabsType: "custom", //
          titleText: "返回",
          title: "",
          searchValKey: [],
          popupColumns: [],
          custTabs: [{
            "type": "InputSelect",
            "inputType": "enum",
            "colName": "promotion_name",
            // "type": "input",
            // "inputType": "String",
            "parent": "",
            "is_count": false,
            "show_expr": {},
            "label": "促销标题",
            "showLabel": true,
            "default": "",
            "colspan": 24,
            "showAllTag": false,
            "tags": []
          }, {
            "colName": "promotion_mode",
            "type": "Select",
            "inputType": "enum",
            "parent": "",
            "is_count": false,
            "show_expr": {},
            "label": "促销模式",
            "showLabel": true,
            "default": "",
            "colspan": 24,
            "showAllTag": false,
            "tags": [],
            "option_list_v2": [{
                label: "全部模式",
                value: '全部模式'
              },
              {
                label: "满额减现",
                value: '满额减现'
              },
              {
                label: "直接折扣",
                value: '直接折扣'
              }
            ]
          }, {
            "colName": "promotion_state",
            "type": "Select",
            "inputType": "enum",
            "parent": "",
            "is_count": false,
            "show_expr": {},
            "label": "促销状态",
            "showLabel": true,
            "default": "",
            "colspan": 24,
            "showAllTag": false,
            "tags": [],
            "appendSearchButton": true,
            tabsType:'custom',
            "custom_options": [{
                text: "未生效",
                value: '未生效'
              },
              {
                text: "生效",
                value: '生效'
              },
              {
                text: "已失效",
                value: '已失效'
              },
              {
                text: "已过期",
                value: '已过期'
              }
            ]
          }],
          tabs: {
            layout: 'inline', // 'inline'   block
          }
        },
        condition: [],
        list: [],
        loaded:false
      };
    },
    components: {
      rList
    },
    onShow() {
      this?.$refs?.rList?.getTableDatas()
    },
    created() {
      this.getAllPromotionName()
    },
    methods: {
      async getAllPromotionName() {
        const url = `/mkt/select/srvmkt_promotion_activity_select`
        const req = {
          "serviceName": "srvmkt_promotion_activity_select",
          "colNames": ["*"],
          group: [{
            "colName": "promotion_name",
            "type": "by"
          }],
          // condition:[{
          //   colName:'coupon_title',
          //   ruleType:'ne'

          // }],
          "page": {
            "pageNo": 1,
            "rownumber": 999,
          }
        }
        const res = await this.$http.post(url, req)
        if (res.data?.state === 'SUCCESS') {
          this.warConfig.custTabs[0].custom_options = res.data.data.map(item => {
            return {
              label: item.promotion_name,
              text: item.promotion_name,
              value: item.promotion_name
            }
          })

        }
        this.loaded = true
      },
      onGridButton(e) {
        console.log('onGridButton', e);
      },
      onItemChecked(e) {
        console.log('onItemChecked', e);
      },
    }
  }
</script>

<style lang="scss" scoped>
  .retail-list .retail-list-right {
    height: calc(100vh-190rpx) !important;
  }
</style>
